package com.sky.controller.common;

import com.sky.exception.BaseException;
import com.sky.result.Result;
import com.sky.service.common.CommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 公共模块
 *
 * @Author: Zhy
 * @Date: 2025-01-19 19:53
 * @Version: 1.0
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(tags = "公共模块")
public class CommonController {
	private final CommonService commonService;

	@ApiOperation("上传图片")
	@PostMapping("/admin/common/upload")
	public Result<String> upload(@RequestParam("file") MultipartFile file) {
		try {
			return commonService.upload(file.getBytes(), file.getOriginalFilename());
		} catch (IOException e) {
			throw new BaseException("图片上传失败！");
		}
	}
}
